//**************************************************************
//		AHDataSource.h
//			AppHider
//
//	Copyright (c) 2008 Metta Media
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//**************************************************************
#import <Cocoa/Cocoa.h>
#import <OSAKit/OSAKit.h>
#import "Node.h"
#import "AHPreferences.h"
#import "ApplicationMenu.h"
#import "PrefPaneController.h"
#import "AHTableView.h"
#import "SRRecorderControl.h"
#import "MABSupportFolder.h"

@interface AHDataSource : NSObject
{
	IBOutlet NSTabView *mainView;
	IBOutlet NSTabView *sidebarTab;
	
    // I am the data source of this outline view
    IBOutlet NSOutlineView *outlineView;
	IBOutlet id appTable;
    
	IBOutlet id addAppExtraView;
	IBOutlet id addDefaultMenuItemsButton;
	IBOutlet id hideDockIconButtonInAdd;
	
    // This node is the root of the tree being displayed
	IBOutlet id controller;
	AHPreferences * AHPrefs;
	IBOutlet MABSupportFolder * supportFolder;
	IBOutlet id enableOnStartUpButton;
	IBOutlet id checkForUpdatesButton;
	IBOutlet id appDirection;
	IBOutlet id restartDaemonOnChange;
	NSMutableArray * appArray;
	NSMutableArray * appOrder;
	id selectedItem;
    ApplicationMenu * rootNode;
	BOOL isUpdating;
	NSNotificationCenter * notificationCenter;
	
	//app display
	IBOutlet id appTitle;
	IBOutlet id appIcon;
	IBOutlet id iconCheckbox;
	
	//Add/edit children
	BOOL editNode;
	IBOutlet id optionsPanel;
	IBOutlet id actionsTabView;
	IBOutlet id keystrokeName;
	IBOutlet id keystroke;
	IBOutlet id applescriptName;
	IBOutlet id applescriptEditor;
	IBOutlet id applescriptController;
	IBOutlet id applescriptRecordButton;
	IBOutlet id submenuName;
	
	IBOutlet id advPrefGrayScale;
	IBOutlet id advPrefTitle;
	IBOutlet id advPrefTooltip;
	BOOL advancedSettingsOn;
	
}
-(void)readApplicationPlists;
-(void)updateAppTable;
-(void)syncOSAObjects:(NSNotification *)note;
-(void)importAppFromPath:(NSString*)path;
-(void)addApp:(NSString *)filename withDefaults:(NSDictionary*)dict;
-(IBAction)openAddAppPanel:(id)sender;
-(void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo;
-(IBAction)removeApp:(id)sender;
-(void)removeAppAlertDidEnd:(NSWindow *)window returnCode:(int)returnCode contextInfo:(void *)contextInfo;
-(NSString*)nameOfSelectedApplication;
// This is the method triggered by the button
-(IBAction)addChild:(id)sender;
-(IBAction)editChild:(id)sender;
-(IBAction)addEditAppItem:(id)sender;
-(IBAction)removeChild:(id)sender;
- (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason;
-(IBAction)recordScript:(id)sender;
-(IBAction)stopRecordScript:(id)sender;
-(IBAction)importScript:(id)sender;
-(IBAction)changeIcon:(id)sender;
//-(IBAction)revealInFinder:(id)sender;
-(IBAction)contextMenu:(id)sender;
-(IBAction)toggleAdvancedSettings:(id)sender;
-(IBAction)saveAdvancedSettings:(id)sender;

// These methods get called because I am the datasource of 
// the outline view.
- (id)outlineView:(NSOutlineView *)outlineView 
    child:(int)index 
    ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView 
    isItemExpandable:(id)item;
- (int)outlineView:(NSOutlineView *)outlineView 
    numberOfChildrenOfItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView 
	shouldEditTableColumn:(NSTableColumn *)tableColumn 
	item:(id)item;
- (id)outlineView:(NSOutlineView *)outlineView 
    objectValueForTableColumn:(NSTableColumn *)tableColumn 
    byItem:(id)item;

- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard;
- (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)childIndex;
- (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)childIndex;

- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;	
- (void)selectAppAndSetMainView;
- (void)savePlist;
- (BOOL)saveAppTo:(NSString*)path extension:(NSString*)ext;
- (void)addAppFromDragNDrop:(NSString*)filename;

- (IBAction)toggleIconVisibility:(id)sender;
-(void)iconAlertDidEnd:(NSWindow *)window returnCode:(int)returnCode contextInfo:(void *)contextInfo;
-(void)relaunchDeamon;
-(IBAction)actOnPref:(id)sender;
-(IBAction)changeAppDirection:(id)sender;
-(void)setPrefs;
-(void)savePrefs;

// Accessor Methods

@end
